package com.mayikt.member.impl;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Test {

    public static void main(String[] args) {
        Enumeration<NetworkInterface> networks = null;
        try {
            // 获取网卡设备
            networks = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException e) {
//            logger.info(e.getMessage());
        }
        InetAddress ip = null;
        Enumeration<InetAddress> addrs;
        // 遍历网卡设备
        while (networks.hasMoreElements()){
            addrs = networks.nextElement().getInetAddresses();
            while (addrs.hasMoreElements()){
                ip = addrs.nextElement();
                if (ip != null && ip instanceof InetAddress && ip.isSiteLocalAddress()){
                    if (ip.getHostAddress()==null || "".equals(ip.getHostAddress())){
//                        logger.info("获取到的客户端内网ip为空，从配置文件读取本地ip。");
                    }
                    System.out.println(ip.getHostAddress()); ;// 客户端ip
                }
            }
        }
    }
}
